package com.itheima.web;

import com.itheima.entity.Result;
import com.itheima.service.OrderSettingService;
import com.itheima.utils.POIUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author ：yuanjian
 * @date ：Created in 2020/11/14 19:17
 * @description：
 */
@RestController
@RequestMapping("ordersetting")
public class OrderSettingController {

    @Reference
    private OrderSettingService orderSettingService;

    //批量导入预约设置信息
    @PostMapping("importOrderSettings")
    public Result importOrderSettings(@RequestParam("excelFile")MultipartFile file) throws IOException {
            List<String[]> list = POIUtils.readExcel(file);
            // string[0]   日期   string[1]    最大预约数
            orderSettingService.batchOrderSetting(list);
            return  new Result(true);
    }

    @GetMapping("findSettingData/{year}/{month}")
    public Result findSettingData(@PathVariable("year") String  year, @PathVariable("month") String  month){
            Map mapList = orderSettingService.findSettingData(year,month);
            return  new Result(true,"查询成功",mapList);

    }

    //        后台手动设置最大预约数
    @PutMapping("updateOrderSettingData/{orderDate}/{num}")
    public Result updateOrderSettingData(@PathVariable("orderDate") String  orderDate ,@PathVariable("num") Integer num) {
            orderSettingService.updateOrderSettingData(orderDate,num);
            return new Result(true,"修改成功");
    }
}
